package info.nixbear.tgcms.admin.client.place;

import info.nixbear.tgcms.admin.shared.request.RedirectProxy;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;

public class RedirectsPlace extends Place {
	
	public static class RedirectEditPlace extends RedirectsPlace {
		String token;
		RedirectProxy redirect;
		
		public RedirectEditPlace(String token, RedirectProxy redirect) {
			this.token = token;
			this.redirect = redirect;
		}

		public String getToken() {
			return token;
		}
		
		public RedirectProxy getRedirect() {
			return redirect;
		}

		public static final String newToken = "new";
		
		public boolean isTokenANewToken() {
			return newToken.equals(token);
		}
	}
	
	@Prefix("redirects")
	public static class Tokenizer implements PlaceTokenizer<RedirectsPlace> {

		@Override
		public RedirectsPlace getPlace(String token) {
			return (token==null || token.isEmpty())?new RedirectsPlace():new RedirectEditPlace(token, null);
		}

		@Override
		public String getToken(RedirectsPlace place) {
			return (place instanceof RedirectEditPlace)?((RedirectEditPlace) place).getToken():"";
		}
		
	}

}
